dnd: simplify code
authorBenjamin Otte <otte@redhat.com>
Sun, 16 Feb 2020 17:32:42 +0000 (18:32 +0100)
committerBenjamin Otte <otte@redhat.com>
Mon, 17 Feb 2020 03:04:21 +0000 (04:04 +0100)
The old code did mimetype checks everywhere when type compatibility has
since been moved to the GtkDropTarget::accept signal.

So the code can now just assume a compatible mime type exists.

gtk/gtktext.c
gtk/gtktextview.c
tests/testdnd3.c

index 6dce1b327bde515b037e2c41342375c8870e071b..c7ca23be88fc51878e7a9426777af8dfa888e724 100644 (file)
@@ -6229,21 +6229,14 @@ gtk_text_drag_accept (GtkDropTarget *dest,
                       GtkText       *self)
 {
   GtkTextPrivate *priv = gtk_text_get_instance_private (self);
-  GdkDragAction suggested_action;
 
-  if (priv->editable &&
-      gtk_drop_target_find_mimetype (dest) != NULL)
-    {
-      suggested_action = GDK_ACTION_COPY | GDK_ACTION_MOVE;
-    }
-  else
-    {
-      /* Entry not editable, or no text */
-      suggested_action = 0;
-    }
+  if (!priv->editable)
+    return FALSE;
 
-  gdk_drop_status (drop, suggested_action);
-  return suggested_action != 0;
+  if ((gdk_drop_get_actions (drop) & gtk_drop_target_get_actions (dest)) == 0)
+    return FALSE;
+
+  return gdk_content_formats_match (gtk_drop_target_get_formats (dest), gdk_drop_get_formats (drop));
 }
 
 static void
@@ -6259,8 +6252,7 @@ gtk_text_drag_motion (GtkDropTarget *dest,
   old_position = priv->dnd_position;
   new_position = gtk_text_find_position (self, x + priv->scroll_offset);
 
-  if (priv->editable &&
-      gtk_drop_target_find_mimetype (dest) != NULL)
+  if (priv->editable)
     {
       if (priv->selection_bound == priv->current_pos ||
           new_position < priv->selection_bound ||
index 5f677847a1000ce67782643b6ddf924980383819..9ca2659e18a852b51db020046c488e0de17800e8 100644 (file)
@@ -7781,7 +7781,6 @@ gtk_text_view_drag_motion (GtkDropTarget *dest,
   GtkTextIter end;
   GdkRectangle target_rect;
   gint bx, by;
-  GdkAtom target;
   gboolean can_accept = FALSE;
 
   target_rect = priv->text_window->allocation;
@@ -7801,16 +7800,10 @@ gtk_text_view_drag_motion (GtkDropTarget *dest,
                                      &newplace,
                                      bx, by);  
 
-  target = gtk_drop_target_find_mimetype (dest);
-
-  if (target == NULL)
-    {
-      /* can't accept any of the offered targets */
-    }                                 
-  else if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
-                                                 &start, &end) &&
-           gtk_text_iter_compare (&newplace, &start) >= 0 &&
-           gtk_text_iter_compare (&newplace, &end) <= 0)
+  if (gtk_text_buffer_get_selection_bounds (get_buffer (text_view),
+                                            &start, &end) &&
+      gtk_text_iter_compare (&newplace, &start) >= 0 &&
+      gtk_text_iter_compare (&newplace, &end) <= 0)
     {
       /* We're inside the selection. */
     }
index 67a0b61065ae1d73e154b87dbe1d11257835b48f..b1c4a47dc8644e85b2e51591ef3ff9b33444efa0 100644 (file)
@@ -213,26 +213,8 @@ item_drag_drop (GtkDropTarget *dest,
                int            x,
                int            y)
 {
-  if (gtk_drop_target_find_mimetype (dest))
-    {
-      gdk_drop_read_value_async (drop, GDK_TYPE_RGBA, G_PRIORITY_DEFAULT, NULL, got_color, dest);
-      return TRUE;
-    }
-
-  return FALSE;
-}
-
-static gboolean
-item_drag_motion (GtkDropTarget *dest,
-                  GdkDrop       *drop)
-{
-  if (gtk_drop_target_find_mimetype (dest) != NULL)
-    {
-      gdk_drop_status (drop, GDK_ACTION_COPY);
-      return TRUE;
-    }
-
-  return FALSE;
+  gdk_drop_read_value_async (drop, GDK_TYPE_RGBA, G_PRIORITY_DEFAULT, NULL, got_color, dest);
+  return TRUE;
 }
 
 static void
@@ -307,7 +289,6 @@ canvas_item_new (int i,
   formats = gdk_content_formats_new_for_gtype (GDK_TYPE_RGBA);
   dest = gtk_drop_target_new (formats, GDK_ACTION_COPY);
   g_signal_connect (dest, "drag-drop", G_CALLBACK (item_drag_drop), NULL);
-  g_signal_connect (dest, "accept", G_CALLBACK (item_drag_motion), NULL);
   gtk_widget_add_controller (widget, GTK_EVENT_CONTROLLER (dest));
   gdk_content_formats_unref (formats);